package com.ambow.restaurant.sys.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ambow.restaurant.sys.po.Order;
import com.ambow.restaurant.sys.service.IOrderService;
import com.ambow.restaurant.sys.service.OrderServiceIMPL;
import com.ambow.restaurant.test.sysFoodTest;

/**
 * Servlet implementation class SysOrderServlet
 */
@WebServlet("/sys/orderList.do")
public class SysOrderServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    IOrderService orderService = new OrderServiceIMPL();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SysOrderServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String method = request.getParameter("method");
		System.out.println(method);
		if(method.equals("list")&&method != null) {
			List<Order> orderList = orderService.findAll();
			request.setAttribute("orders", orderList);
			request.getRequestDispatcher("/jsp/sys/orderList.jsp").forward(request, response);
		}else if(method.equals("update")&&method != null){
			String sid = request.getParameter("id");
			String disableds = request.getParameter("disabled");
			Integer disabled = Integer.parseInt(disableds);
			Integer id = Integer.parseInt(sid);
			Order order = orderService.getById(id);
			order.setDisabled(disabled);
			orderService.update(order);
			response.sendRedirect(getServletContext().getContextPath()+"/sys/orderList.do?method=list");
		}
	}

}
